/*
 * @Autor: dingxiaolin
 * @Date: 2021-06-02 13:12:45
 * @LastEditors: dingxiaolin
 * @LastEditTime: 2021-07-26 14:35:46
 */
import http from '@/utils/http/axios'
import qs from 'qs'
import { Base64 } from 'js-base64'
import { type } from './interface'
import setting from '@/config/defaultSettings'
const { clientId, clientSecret } = setting

/**
 * @description: 获取验证码图片
 */
export function getImgCaptcha(params) {
    return http.request<type.captcha>({
        url: `/app-admin/dnl/auth/captcha`,
        method: 'POST',
        params
    })
}
/**
 * @description: 用户登录
 */
export function login(params) {
    return http.request<any>({
        url: `/app-admin/dnl/auth/token`,
        method: 'POST',
        headers: {
            Authorization: `Basic ${Base64.encode(`${clientId}:${clientSecret}`)}`
        },
        params,
    })
}

/**
 * @description: 获取用户信息
 */
export function getUserInfo() {
    return http.request<any>({
        url: '/app-admin/user/getLoginUser',
        method: 'GET'
    })
}

/**
 * @description: 用户注销
 */
export function newlogout(params) {
    return http.request<any>({
        url: `/app-admin/dnl/auth/outLine?${qs.stringify(params)}`,
        method: 'POST'
    })
}
/**
 * @description: 系统用户管理列表
 */
export function getUserList(params) {
    return http.request<any>({
        url: '/app-admin/user/page',
        method: 'GET',
        params
    })
}
/**
 * @description: 切换用户状态
 */
export function changeStatus(params) {
    return http.request<any>({
        url: '/app-admin/user/changeStatus',
        method: 'POST',
        params
    })
}
/**
 * 获取机构树
 */
export function getOrgTree() {
    return http.request<any>({
        url: '/app-admin/org/tree',
        method: 'GET',
    })
}
/**
 * 获取机构树
 */
export function getOrgList() {
    return http.request<any>({
        url: '/app-admin/org/list',
        method: 'GET',
    })
}
/**
 * 系统职位列表
 */
export function sysPosList() {
    return http.request<any>({
        url: '/app-admin/pos/list',
        method: 'GET',
    })
}
/**
 * 增加用户
 */
export function sysUserAdd(params) {
    return http.request<any>({
        url: '/app-admin/user/add',
        method: 'POST',
        params
    })
}
/**
 * 编辑用户
 */
export function sysUserEdit(params) {
    console.log('data', params)
    return http.request<any>({
        url: '/app-admin/user/edit',
        method: 'POST',
        params
    })
}
/**
 * 重置密码
 */
export function sysUserResetPwd(params) {
    return http.request<any>({
        url: '/app-admin/user/resetPwd',
        method: 'POST',
        params
    })
}
/**
 * 删除用户
 */
export function sysUserDelete(params) {
    return http.request<any>({
        url: '/app-admin/user/delete',
        method: 'POST',
        params
    })
}
/**
 * 拥有角色
 */
export function sysUserOwnRole(params) {
    return http.request<any>({
        url: '/app-admin/user/ownRole',
        method: 'GET',
        params
    })
}

/**
 * 授权角色
 */
export function sysUserGrantRole(params) {
    return http.request<any>({
        url: '/app-admin/user/grantRole',
        method: 'POST',
        params
    })
}
/**
 * 获取用户详情
 */
export function sysUserDetail(params) {
    return http.request<any>({
        url: '/app-admin/user/detail',
        method: 'GET',
        params
    })
}
/**
 * 修改状态
 */
export function sysUserChangeStatus(params) {
    return http.request<any>({
        url: '/app-admin/user/changeStatus',
        method: 'POST',
        params
    })
}

/**
 * 拥有数据
 */
export function sysUserOwnData(params) {
    return http.request<any>({
        url: '/app-admin/user/ownData',
        method: 'GET',
        params
    })
}

/**
 * 授权数据
 */
export function sysUserGrantData(params) {
    return http.request<any>({
        url: '/app-admin/user/grantData',
        method: 'POST',
        params
    })
}
/**
 * 更新基本信息
 */
export function sysUserUpdateInfo(params) {
    return http.request<any>({
        url: '/app-admin/user/updateInfo',
        method: 'POST',
        params
    })
}

/**
 * 修改密码
 */
export function sysUserUpdatePwd(params) {
    return http.request<any>({
        url: '/app-admin/user/updatePwd',
        method: 'POST',
        params
    })
}